#ifndef CCON_H_INCLUDED
#define CCON_H_INCLUDED

#include <stdio.h>
#include <malloc.h>


#define PROPAGATABLE cconres_t _res
#define PROPAGATE if(_res < 0) return _res
#define CCONRES_OKAY               (0) 
#define CCONRES_END_OF_STREAM      (-1) 
#define CCONRES_OUT_OF_MEMORY      (-2) 
#define CCONRES_WRONG_COUNT        (-3) 

typedef int cconres_t;

typedef struct {
	size_t (*read)(void * self, char * buf, size_t count);
	size_t (*write)(void * self, char * buf, size_t count);
	long (*tell)(void * self);
	long (*seek)(void * self, long offset);
	void * self;
} stream_t;

typedef struct {
	char * buf;
	size_t size;
	long offset;
} memstream_t;


cconres_t ccon_ubint8_parse(unsigned char * out, stream_t * stream);
cconres_t ccon_sbint8_parse(signed char * out, stream_t * stream);
cconres_t ccon_ulint8_parse(unsigned char * out, stream_t * stream);
cconres_t ccon_slint8_parse(signed char * out, stream_t * stream);
cconres_t ccon_ubint16_parse(unsigned short * out, stream_t * stream);
cconres_t ccon_sbint16_parse(signed short * out, stream_t * stream);
cconres_t ccon_ulint16_parse(unsigned short * out, stream_t * stream);
cconres_t ccon_slint16_parse(signed short * out, stream_t * stream);
cconres_t ccon_ubint32_parse(unsigned long * out, stream_t * stream);
cconres_t ccon_sbint32_parse(signed long * out, stream_t * stream);
cconres_t ccon_ulint32_parse(unsigned long * out, stream_t * stream);
cconres_t ccon_slint32_parse(signed long * out, stream_t * stream);

cconres_t memstream_init(stream_t * stream, memstream_t * self, char * buf, size_t size);
cconres_t filestream_init(stream_t * stream, FILE * self);



#endif /* CCON_H_INCLUDED */
